package com.mergeades.chp04;

public class JoinTest {

    public static void main(String[] args) {
        Thread prev = Thread.currentThread();
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Demion(prev), "Thread-" + i);
            t.start();
            prev = t;
        }
    }

    static class Demion implements Runnable {

        private Thread thread;

        public Demion(Thread thread) {
            this.thread = thread;
        }

        @Override
        public void run() {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " terminate.");
        }
    }
}
